﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;

namespace SynoManager.GUI
{
    public partial class UpdateForm : Form
    {
        private readonly UpdateChecker.UpdateInfo updateInfo;

        private const string htmlDecorationPre =
            @"<html><head><style>body { background-color: window; color: windowText; font: 8pt Tahoma, Verdana, Arial, sans-serif; }</style></head><body>";
        private const string htmlDecorationPost = @"</body></html>";

        public UpdateForm()
        {
            InitializeComponent();
        }

        public UpdateForm(UpdateChecker.UpdateInfo updateInfo)
            :this()
        {
            this.updateInfo = updateInfo;
            onlineVersionLabel.Text = updateInfo.Title;
            localVersionLabel.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            webBrowser1.DocumentText = htmlDecorationPre + updateInfo.Info + htmlDecorationPost;
        }

        public UpdateForm(UpdateChecker.UpdateInfo updateInfo, bool showDisableCheckBox)
            :this(updateInfo)
        {
            disableAutoCheckBox.Visible = showDisableCheckBox;
        }

        private void viewReleaseLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(updateInfo.Url);
        }

        private void disableAutoCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            Properties.Settings.Default.AutoCheckUpdates = !disableAutoCheckBox.Checked;
        }
    }
}
